<?php

namespace App\Containers\AppSection\Questionnaire\Models;

use App\Containers\AppSection\LegalForm\Models\LegalForm;
use App\Ship\Parents\Models\Model;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * Анкета
 *
 * @property int $id Id
 * @property string $legal_form_type Тип правовой формы
 * @property int $legal_form_id Id  правовой формы
 * @property Carbon $created_at Время создания
 * @property Carbon $updated_at Время обновления
 *
 * @property Response[] $responses Ответы
 * @property LegalForm $legal_form Правовая форма
 */
class Questionnaire extends Model
{
    protected $fillable = [
        'legal_form_id',
        'legal_form_type',
    ];

    protected $dates = [
        'created_at',
        'updated_at',
    ];

    /**
     * A resource key to be used in the serialized responses.
     */
    protected string $resourceKey = 'Questionnaire';
    protected $table = 'questionnaires';

    /**
     * Ответы
     * @return HasMany|Response Responses
     */
    public function responses(): HasMany
    {
        return $this->hasMany(Response::class, 'questionnaire_id', 'id')->orderBy("id");
    }

    /**
     * Правовая форма
     * @return BelongsTo LegalForm
     */
    public function legal_form(): BelongsTo
    {
        return $this->belongsTo(LegalForm::class, 'legal_form_id', 'id');
    }
}
